API: accessible: Add widget_set and widget_unset vfuncs
authorBenjamin Otte <otte@redhat.com>
Sun, 18 Dec 2011 11:55:41 +0000 (12:55 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 19 Dec 2011 15:17:12 +0000 (16:17 +0100)
I expect them to be used a lot, so this approach seems better than
requiring signals that connect to "notify::widget". Also, we can't use
regular functions (like dispose or constructed), becaiuse those assume
that (un)setting of the widget only happens once and with the current
design (a puble set_widget() function) we can't really guarantee that.

Also, I split them into two separate functions as one function is part
of construction and the other part of destruction of the object. And it
doesn't sound like a good idea to have that both be part of one
function.

gtk/gtkaccessible.c
gtk/gtkaccessible.h

index eb318e1cc1a7e95e7f5a3634cae320150a695f8a..e999b092d7c2a8c8f591e3a625bea7239130f255 100644 (file)
@@ -103,12 +103,24 @@ gtk_accessible_init (GtkAccessible *accessible)
                                                   GtkAccessiblePrivate);
 }
 
+static void
+gtk_accessible_real_widget_set (GtkAccessible *accessible)
+{
+}
+
+static void
+gtk_accessible_real_widget_unset (GtkAccessible *accessible)
+{
+}
+
 static void
 gtk_accessible_class_init (GtkAccessibleClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
   klass->connect_widget_destroyed = gtk_accessible_real_connect_widget_destroyed;
+  klass->widget_set = gtk_accessible_real_widget_set;
+  klass->widget_unset = gtk_accessible_real_widget_unset;
 
   gobject_class->get_property = gtk_accessible_get_property;
   gobject_class->set_property = gtk_accessible_set_property;
@@ -142,16 +154,24 @@ gtk_accessible_set_widget (GtkAccessible *accessible,
                            GtkWidget     *widget)
 {
   GtkAccessiblePrivate *priv;
+  GtkAccessibleClass *klass;
 
   g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
 
   priv = accessible->priv;
+  klass = GTK_ACCESSIBLE_GET_CLASS (accessible);
 
   if (priv->widget == widget)
     return;
 
+  if (priv->widget)
+    klass->widget_unset (accessible);
+
   priv->widget = widget;
 
+  if (widget);
+    klass->widget_set (accessible);
+
   g_object_notify (G_OBJECT (accessible), "widget");
 }
 
index 04d213a3a328f157494619a74a32875a107eae80..296186ca2bbbdeecbc4bcff29a5ffecde2761b0a 100644 (file)
@@ -54,9 +54,9 @@ struct _GtkAccessibleClass
 
   void (*connect_widget_destroyed) (GtkAccessible *accessible);
 
+  void (*widget_set)               (GtkAccessible *accessible);
+  void (*widget_unset)             (GtkAccessible *accessible);
   /* Padding for future expansion */
-  void (*_gtk_reserved1) (void);
-  void (*_gtk_reserved2) (void);
   void (*_gtk_reserved3) (void);
   void (*_gtk_reserved4) (void);
 };